<template>
  <detail-dialog modal   showReset  :title="title" :show.sync="show" @reset="resetForm" @update:show="updateShow" :top="5" @save="save">
    <el-form :model="editOrderInfo" label-width="140px" ref="orderInfoForm">
        <el-form-item label="退货类型" prop="returnType" :rules="{ required: true, message: '不能为空', trigger: 'blur' }">
           <el-select style="width: 90%" @change="onSelectReturnType" clearable v-model="editOrderInfo.returnType"  placeholder="请选择">
                  <el-option v-for="(item,index) in returnTypes" :key="index" :label="item.label" :value="item.value"></el-option>
            </el-select>
        </el-form-item>
      <el-form-item label="商定退货日期" prop="returnDate" :rules="{ required: true, message: '不能为空', trigger: 'blur' }">
        <el-date-picker
          style="width: 90%"
          v-model="editOrderInfo.returnDate"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="date" clearable
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="退款金额" prop="returnTotalAmount" :rules="{ required: editOrderInfo.returnType!==0, message: '不能为空', trigger: 'blur' }">
        <el-input
          style="width: 90%"
          :disabled="editOrderInfo.returnType===0"
          v-model="editOrderInfo.returnTotalAmount"
          placeholder="退款金额" clearable
        ></el-input>
      </el-form-item>
     <el-form-item label="负责人" prop="chargePerson" :rules="{ required: true, message: '不能为空', trigger: 'blur' }">
        <Employee-seach   style="width: 90%" :employeeCode.sync="editOrderInfo.chargePerson" :employeeName.sync="editOrderInfo.chargePersonName"/>
     </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input
          style="width: 90%"
          type="textarea"
          v-model="editOrderInfo.remark"
          placeholder="备注"
        ></el-input>
      </el-form-item>
    </el-form>
  </detail-dialog>
</template>
<script>
import DetailDialog from '@/components/DetailDialog'
import returnOrder from '@/api/eims/returnOrderAPI'
import EmployeeSeach from '@/views/components/EmployeeSeach'
import Common from '@/views/mixins/common'
export default {
  name: 'order_base',
  props: {
    title: {type: String, default: '编辑基本信息'},
    visible: {
      type: Boolean,
      default: false
    },
    param: {type: Object,
      default: () => {
        return {}
      }}
  },
  components: { EmployeeSeach, DetailDialog },
  mixins: [Common],
  created () {
    this.salesOrderTypes = this.getSalesOrderTypes()
  },
  computed: {
    returnTypes () {
      return this.getReturnTypes()
    }
  },
  watch: {
    show (nVal) {
      this.$emit('update:visible', nVal)
    },
    visible: {
      handler (val) {
        this.show = val
        this.editOrderInfo = {...this.param}
      },
      immediate: true
    }
  },
  data () {
    return {
      editOrderInfo: {},
      show: this.visible,
      salesOrderTypes: [],
      rules: {
        orderCreateDate: [{ required: true, message: '不能为空', trigger: 'blur' }]
      }
    }
  },
  methods: {
    onSelectReturnType (val) {
      if (val === 0) {
        this.$set(this.editOrderInfo, 'returnTotalAmount', null)
      }
    },
    save () {
      this.$refs.orderInfoForm.validate(valid => {
        if (valid) {
          const params = {}
          params.returnNo = this.editOrderInfo.returnNo
          params.returnType = this.editOrderInfo.returnType
          params.returnDate = this.editOrderInfo.returnDate
          params.returnTotalAmount = this.editOrderInfo.returnTotalAmount
          params.chargePerson = this.editOrderInfo.chargePerson
          params.chargePersonName = this.editOrderInfo.chargePersonName
          params.remark = this.editOrderInfo.remark
          returnOrder.updateReturnOrderInfoAPI(params).then(res => {
            if (res.code === 0) {
              this.show = false
              this.$emit('saveAfter', this.editOrderInfo.returnNo)
            }
          })
        }
      })
    },
    updateShow (val) {
      this.show = val
    },
    resetForm () {
      this.$refs.orderInfoForm.resetFields()
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
